/**
*      author: Y_Yao
*      created: 2024-12-08 18:35:30
**/

#include<bits/stdc++.h>

//#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 7;
int h,w,d;
char a[N][N];
bool vis[N][N];
int ans = 0;
int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};

vector<vector<int>> dist(N,vector<int>(N,INF));

struct node
{
    int x,y,step;
};

void bfs()
{
    queue<pair<int,int>> q;
    for(int i = 1;i <= h;i++)
    {
        for(int j = 1;j <= w;j++)
        {
            if(a[i][j] == 'H')
            {
                q.push({i,j});
                dist[i][j] = 0;
            }
        }
    }

    while(!q.empty())
    {
        auto t = q.front();
        q.pop();
        int ta = t.first,tb = t.second;

        if(vis[ta][tb]) continue;
        vis[ta][tb] = true;
        for(int k = 0;k < 4;k++)
        {
            int x = ta + dx[k],y = tb + dy[k];
            if(x < 1 || x > h || y < 1 || y > w || a[x][y] == '#') continue;
            dist[x][y] = min(dist[x][y],dist[ta][tb] + 1);
            q.push({x,y});
        }
    }
}

void solve()
{
    cin >> h >> w >> d;
    for(int i = 1;i <= h;i++)
    {
        for(int j = 1;j <= w;j++)
        {
            cin >> a[i][j];
        }
    }

    bfs();

    for(int i = 1;i <= h;i++)
    {
        for(int j = 1;j <= w;j++)
        {
            if(dist[i][j] <= d)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}